import { get, post, IList } from "./index";

export interface Role {
    id: number;
    name: string;
}
// 获取角色列表
export const getRoles = async (data: {
    name: string;
    page: number;
    pageSize: number;
}): Promise<IList<Role>> => {
    const res = await post("/role/list", data);
    return res.data;
};

// 新增角色
export const addRole = async (data: { name: string }) => post("/role/create", data);

interface EditRole {
    id: number;
    name: string;
}
// 编辑角色
export const editRole = async (data: EditRole) => post("/role/update", data);

// 删除角色
export const delRole = async (id: number) => post("/role/delete", { id });

// 查询角色权限
export const getRolePremissons = async (id: number): Promise<number[]> => {
    const res = await post("/role/role/permission", { id });
    return res.data?.permissionList || [];
};

interface UpdateRolePremissons {
    id: number;
    permissionList: number[];
}
// 修改角色权限
export const updateRolePremissons = async (data: UpdateRolePremissons) => {
    const res = await post("/role/role/permission/update", data);
    return res.data;
};
